<template>
	<view class="wrap">
		<baseForm :column.sync="column" :button="{hide: true}"></baseForm>
		<progressBox :auditVos="auditVos" dictcode="dict_audit_status"></progressBox>
		<view class="buttons" v-if="getApprovalShow('applyStatus')">
			<button size="mini" class="middleButton" @click="pass('会议', itemData)">通过</button>
			<button size="mini" class="middleButton" @click="unpass('会议', itemData)">不通过</button>
		</view>
	</view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import login from '@/libs/login.js';
import { format, dectList } from '@/libs/common.js';
import { mapGetters } from 'vuex';
import userMixins from '@/libs/userMixins.js'
import approvalMixins from '@/libs/approvalMixins.js'
import formMixins from '@/libs/formMixins.js'
import progressBox from '@/wxcomponents/commonLayout/progressLevel.vue';
export default {
	mixins: [userMixins, approvalMixins, formMixins],
	data() {
		let self = this;
		return {
			itemData: '',
			auditVos: '',
			column: [
				{
					label: '会议名称', //输入框title
					name: 'meetingName', //传值类型
					type: 'normalInput', //输入框类型
					mode: 'date',
					disabled: true, //是否禁用
					required: true, //是否必须填写
					value: '' //输入框的值
				},
				{
					label: '会议日期',
					name: 'meetingDate',
					type: 'picker',
					mode: 'date',
					required: true,
					disabled: true,
					value: format('YY-mm-dd', new Date()),
					text: format('YY-mm-dd', new Date())
				},
				{
					label: '会议起始时间',
					name: 'meetingStart',
					type: 'picker',
					mode: 'time',
					required: true,
					disabled: true,
					value: '',
					text: '请选择'
				},
				{
					label: '会议结束时间',
					name: 'meetingEnd',
					type: 'picker',
					mode: 'time',
					required: true,
					disabled: true,
					value: '',
					text: '请选择'
				},
				{
					label: '会议室',
					name: 'roomId',
					type: 'picker',
					mode: 'selector',
					required: true,
					disabled: true,
					value: '',
					text: '请选择',
					range: []
				},
				{
					label: '会议级别',
					name: 'meetingLevel',
					type: 'picker',
					mode: 'selector',
					required: true,
					disabled: true,
					value: '',
					text: '请选择',
					range: []
				},
				{
					label: '校内参会人员',
					name: 'participantsInner',
					type: 'tips',
					required: true,
					disabled: true,
					value: '',
					text: '',
					url: '/modules/department/departmentMenu',
					hiddenDel: true,
					chooseItems: []
				},
				{
					label: '校外参会人员',
					name: 'participantsOuter',
					type: 'normalInput',
					disabled: true,
					required: false,
					value: '',
					url: ''
				},
				{
					label: '会议内容',
					name: 'meetingDesc',
					type: 'normalInput',
					disabled: true,
					required: false,
					value: ''
				},
				{
					label: '附件',
					type: 'upload',
					url: '/stu/common/uploadFile',
					docFileId: '',
					docFileUrl: '',
					docFileName: '',
					attachmentVoListStr: '',
					limitSize: 9,
					disabled: true
				}
			]
		};
	},
	async onLoad(option) {
		await this.getMeetingRoom();
		await this.getMeetLevel();
		this.itemData = JSON.parse(option.data);
		this.getDetail(this.itemData.id);
	},
	methods: {
		//会议室获取
		async getMeetingRoom() {
			let resp = await this.$http.post({
				url: '/oa/meetingRoom/list'
			});
			this.column[4].range = resp.result.map(item => {
				return {
					name: item.roomName,
					id: item.id,
					value: item.id
				};
			});
			return this.column[4].range
		},
		//会议级别
		async getMeetLevel() {
			let resp = await dectList('dict_meeting_rank');
			this.column[5].range = resp.map(item => {
				return {
					name: item.dictName,
					id: item.dictValue,
					value: item.dictValue
				};
			});
			return this.column[5].range
		},
		async getDetail(id) {
			let self = this;
			// 赋值校内参会人员
			let assignParticipantsInner = (formModel) => {
				let ids = formModel.participantsInner.split(',');
				let names = formModel.participantsInnerName.split(',');
				let chooseItems = ids.map((id, index) => {
					let obj = {
						id,
						name: names[index]
					};
					return obj;
				})
				this.column[6].chooseItems = chooseItems;
			}
			let caseMap = [
				{
					condition() {	// 详情
						return self.itemData.detailType == 'detail'
					},
					async func() {
						let resp = await self.$http.get({
							url: `/oa/meetingApply/detail/${id}`
						});
						self.assignFormDataToViewModel(resp.result, self.column);
						self.auditVos = resp.result.auditVoList;
						assignParticipantsInner(resp.result)
					}
				},
				{
					condition() {	// 审批
						return self.itemData.detailType == 'approval'
					},
					async func() {
						let resp = await self.$http.get({
							url: `/oa/meetingManage/detail/${id}`
						});
						self.assignFormDataToViewModel(resp.result, self.column);
						self.auditVos = resp.result.auditVoList;
						assignParticipantsInner(resp.result)
					}
				},
			]
			let findOne = caseMap.filter(item => {
				return item.condition()
			})[0]
			if (!findOne) {
				alert(`getDetail方法出错`)
			}
			findOne.func();
		},
	},
	components: {
		baseForm,
		progressBox
	},
	computed: {
		
	}
};
</script>

<style lang="scss" scoped>
page {
	min-height: 100%;
}
.wrap {
	height: 100%;
}
</style>
